home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / keybd.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  3KB  |  83 lines

  1. /****************************************************************
  2. *                                                               *
  3. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  4. * No part of this program may be reproduced, transmitted,       *
  5. * transcribed, stored in retrieval system, or translated into   *
  6. * any language or computer language, in any form or by any      *
  7. * means, electronic, mechanical, magnetic, optical, chemical,   *
  8. * manual or otherwise, without the prior written permission of  *
  9. * Commodore Amiga Incorporated, 983 University Ave, #D          *
  10. * Los Gatos, CA 95030                                           *
  11. *                                                               *
  12. ****************************************************************/
  13. /* sample program to demonstrate direct communications with the keyboard,
  14.  * won't work unless input device is disabled, so that keyboard can
  15.  * be accessed individually
  16.  *
  17.  * Author: Rob Peck 10/11/85
  18.  */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/io.h>
  22. #include <devices/keyboard.h>
  23. #include <devices/inputevent.h>
  24.  
  25. extern struct Port *CreatePort();
  26. extern struct IOStdReq *CreateStdIO();
  27.  
  28. SHORT error;
  29.  
  30. struct IOStdReq *keyreq;
  31. struct Port *keyport;
  32. struct InputEvent *keydata;     /* pointer into the returned data area
  33.                                    where an input event has been sent */
  34. BYTE keybuffer[sizeof( struct InputEvent )];
  35.  
  36. main()
  37. {
  38.         keyport = CreatePort(0,0);
  39.         if(keyport == 0) { printf("\nError during CreatePort"); 
  40.                            exit(-1); 
  41.                          }              
  42.         keyreq = CreateStdIO(keyport);  
  43.                 /* make an io request block for 
  44.                  * communicating with the keyboard */
  45.         if(keyreq == 0) { printf("\nError during CreateStdIO");
  46.                           DeletePort(keyport);
  47.                           exit(-2); 
  48.                         }
  49.         error = OpenDevice("keyboard.device",0,keyreq,0);
  50.                         /* open the device for access */
  51.  
  52.         if (error != 0) { printf("\nCan't open keyboard!"); 
  53.                           ReturnMemoryToSystem();
  54.                           exit(-100); 
  55.                         }
  56.         keyreq->io_Length = sizeof(struct InputEvent);  
  57.         /* read one event each time we go back to the keyboard */
  58.  
  59.         keyreq->io_Data = keybuffer;    
  60.         /* show where to put the data when read */
  61.  
  62.         keydata = (struct InputEvent *)keybuffer;
  63.  
  64.         keyreq->io_Command = KBD_READEVENT;     /* get an event!! */
  65.  
  66.  
  67.         for(;;)         /* FOREVER */
  68.         {
  69.         printf("\n Ready to retrieve another key\n");
  70.         DoIO( keyreq );
  71.         printf("\n Raw key found this time was %lx",keydata->ie_Code);
  72.         }
  73.         ReturnMemoryToSystem(); /* can't get here because of FOREVER,
  74.                                  * but if user provides an exit..... */
  75. }               
  76.  
  77. ReturnMemoryToSystem()   
  78. {
  79.         DeleteStdIO(keyreq);
  80.         DeletePort(keyport);
  81.         return;
  82. }
  83.